﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using Common;
using Newtonsoft.Json;
using Basic.Business;

public partial class Basic_Background_SystemConfigManage : System.Web.UI.Page
{
    protected string tableList = "";
    protected Hashtable systemConfig = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Buffer = true;
        Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
        Response.Expires = 0;
        Response.CacheControl = "no-cache";
        Response.AppendHeader("Pragma", "No-Cache"); 
        if (!Tools.IsAdminSessionValid())
        {
            Tools.ShowInfo(StringTable.ErrorSessionTimeOut, "../Background/AdminLogin.aspx", "_self");
        }
        systemConfig = BasicHashTableAdmin.GetHashTable("系统基本配置");
        if (!String.IsNullOrEmpty(Request.QueryString["Action"]))
        {
            Result<Object> result = new Result<object>();
            string action = BadChar.ReplaceBadChar(Request.QueryString["Action"]);
            switch (action)
            {
                case "changeSystemConfig":
                    try
                    {
                        if (!RoleAdmin.CheckRole("系统基本配置", (Basic.VO.Admin)Session["admin"]))
                            throw new Exception("你没有这个权限");
                        String hashTableValue = Request.Form["hashTableValue"];
                        string[] hashTableValues = hashTableValue.Split(',');
                        foreach (string _value in hashTableValues)
                        {
                            if (_value.IndexOf("|") > 0)
                                throw new Exception("所填项目不允许包含“|”字符");
                        }
                        systemConfig["系统名称"] = hashTableValues[0];
                        systemConfig["系统URL"] = hashTableValues[1];
                        systemConfig["SMTP服务器地址"] = hashTableValues[2];
                        systemConfig["SMTP邮箱用户名"] = hashTableValues[3];
                        systemConfig["SMTP邮箱密码"] = hashTableValues[4];
                        BasicHashTableAdmin.UpdateHashTableValue("系统基本配置", systemConfig);
                        result.error = false;
                        result.msg = "修改系统基本配置成功！";
                    }
                    catch (Exception ex)
                    {
                        result.error = true;
                        result.msg = ex.Message;
                    }
                    break;
                default:
                    result.error = true;
                    result.msg = StringTable.ErrorUnknowAction;
                    break;
            }
            Response.Write(JavaScriptConvert.SerializeObject(result));
            Response.End();
        }
        else
        {
        }
    }
}
